home *** CD-ROM | disk | FTP | other *** search
- /*
- | file name - DV_MDI.c
- |=======================================================================
- |
- | This program illustrates the creation of an interface using windows
- | routines and incorporating DataViews as part of this interface.
- | In this program MS Windows windows are created in which DataViews views
- | will be displayed. Memory is allocated per window for storage of View
- | specific data such as Screen, Drawport, and View. This data is associated
- | to the MS Window by supplying its handle with SetWindowLong.
- |
- | This program illustrates several aspects of integrating DataViews
- | in an MS Windows based application.
- |
- | First, the application creates a frame window on which to add many
- | client windows to display DataViews. The widget is passed to TscOpenSet,
- | which creates a screen object. The window is created explicitly
- | by the application and passed to TscOpenSet.
- |
- | Second, this application does not use the DataViews event system to poll
- | for events; it uses the routine GetMessage. Using this polling
- | method requires the user dispatch the windows message as well as convert the
- | windows message into a location object which can be utilized by the DataViews
- | event handling mechanisms.
- |
- | Third, a time-out procedure is set up to update the dynamics of
- | each display whenever the interval of time has past.
- |
- | Note: this example will not work properly for views containing
- | DataViews widget-based input objects.
- |
- |=======================================================================
- */
- #include <windows.h>
- #include <memory.h>
-
- /*
- * DV-Tools header files
- */
- #include "std.h" /* <stdio.h> etc., scalar & macro definitions */
- #include "dvstd.h" /* public types & constants */
- #include "dvtools.h" /* constants used by T routines */
- #include "dvGR.h" /* constants used by window mgt & GR routines */
- #include "VOstd.h" /* constants used by VO & VOob routines */
- #include "Tfundecl.h" /* T routines (screens, drawports & views) */
-
- /*
- * Application specific header files
- */
- #include "DV_MDI.h"
-
- LRESULT (CALLBACK * MDI_Winproc)() = NULL ;
-
- /*
- * Instance data for each MDI child window.
- */
- typedef struct _PerWndData
- {
- OBJECT Screen;
- VIEW View;
- DRAWPORT Drawport;
- OBJECT QuitButton;
- UINT idTimer;
- } VIEWDATA, *PVIEWDATA;
-
- /*
- * Function Prototypes
- */
- HWND InitApplication (HANDLE);
- LONG APIENTRY FrameWndProc (HWND, UINT, DWORD, LONG);
- LONG APIENTRY ViewWndProc (HWND, UINT, DWORD, LONG);
- BOOL APIENTRY CloseEnumProc (HWND, LONG);
- BOOL CALLBACK About (HWND, UINT, DWORD, LONG);
- BOOL CALLBACK YesNoProc (HWND, UINT, DWORD, LONG);
- LOCAL BOOL GetViewDataFromWindow(HWND, PVIEWDATA);
- LOCAL BOOL RestartTimerOfWindow(HWND hwnd);
- BOOL YesNo (CHAR *);
- LOCAL BOOL InitDVWindow(HWND, PVIEWDATA, CHAR *);
- LOCAL void TermDVWindow(PVIEWDATA);
- LOCAL void TermApplication(void);
- LOCAL void UpdateDVwindow(PVIEWDATA);
- LOCAL BOOL HandleDVwindowEvents(PVIEWDATA, MSG *);
- LOCAL BOOL CreateMDIView(HWND hwnd, CHAR *ViewName);
-
- /*
- * Global data
- */
- OBJECT Location; /* the DV event representation */
- LPCTSTR YesNoMessage = NULL; /* message string for YESNO dialog */
- HANDLE ghModule; /* current executable name */
- HWND ghwndFrame = NULL; /* frame window handle */
- HWND ghwndClient = NULL; /* MDI client window handle */
- HMENU hFrameMenu; /* frame menu handle */
- HMENU hFrameMenuWindow; /* frame menu window handle */
- HMENU hViewMenu; /* MDI client menu handle */
- HMENU hViewMenuWindow; /* MDI client menu window handle */
-
- /* This var is set to false when an error message box is displayed then,
- * to true when the dialog exits.
- * We check to see that it is true before redrawing DataViews windows.
- * This prevents an infinit cascade of error messages from overflowing the
- * stack.
- */
- LOCAL BOOL ok_to_draw = TRUE;
-
-
- /*-----------------
- * UpdateDVwindow -- This routine is used to update the dynamics
- * of a particular view and drawport in order
- * to create frames for annimation.
- */
- LOCAL void UpdateDVwindow(PVIEWDATA pViewData)
- {
- TviReadData( pViewData->View );
- TdpDrawNext( pViewData->Drawport );
- }
-
- /*-----------------
- * HandleDVwindowEvents -- All events received by the windows queue
- * are handled as windows events. If any events are
- * interpreted by DataViews, they are converted, a
- * location object is created, and processed by DataViews
- * event handling mechanisms.
- */
- LOCAL BOOL HandleDVwindowEvents(PVIEWDATA pViewData, MSG *Message)
- {
- WINEVENT we; /* structure storing details of event */
- CHAR *Name;
- OBJECT SelectedObject;
-
- /*
- * Convert the Windows event into the DataViews window event structure
- * (WINEVENT). The using the window event structure set up a
- * DataViews location object, which is the DataViews representation
- * of the event.
- */
- (VOID)GRwe_convert( (ADDRESS)Message, &we );
- (VOID)TloWinEventSetup( Location, &we, (OBJECT)NULL, (DRAWPORT)NULL );
- if ((SelectedObject = TloGetSelectedObject( Location )) != (OBJECT)NULL)
- if (SelectedObject == pViewData->QuitButton)
- return YES;
- /*
- * DVtools has another way to handle the type of event received based
- * on information in the location object. An event of this type is for
- * a DataViews based input object or another independent
- * object. This event will be dispatched for the user in the
- * DataViews handler, VUerHandleLocEvent. This is demonstrated in another
- * DVtools example.
- */
- return NO;
- }
-
- /*-----------------
- * InitApplication -- All class data and global data are initialized
- * and loaded here.
- */
- HWND InitApplication(HANDLE hInstance)
- {
- WNDCLASS wc;
- HWND hwnd = NULL;
-
- /* Initialize DataViews */
- TInit( NULL, NULL );
-
- /* Reference to current module executing. (.EXE or .DLL) */
- ghModule = GetModuleHandle(NULL);
-
- /* We will need to convert to DataViews events at times so a global
- * location object is created
- */
- if ((Location = VOloCreate()) != (OBJECT)NULL)
- {
- wc.style = CS_OWNDC;
- wc.lpfnWndProc = (WNDPROC) FrameWndProc;
- wc.cbClsExtra = 0;
- wc.cbWndExtra = sizeof(LONG);
- wc.hInstance = ghModule;
- wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
- wc.hCursor = LoadCursor(NULL, IDC_ARROW);
- wc.hbrBackground = (HBRUSH)(COLOR_APPWORKSPACE);
- wc.lpszMenuName = "FrameMenu";
- wc.lpszClassName = MDI_FRAME_CLASS_NAME;
-
- /* Register instance of Frame window class. */
- if (RegisterClass(&wc))
- {
- wc.lpfnWndProc = (WNDPROC) ViewWndProc;
- wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
- wc.lpszMenuName = NULL;
- wc.lpszClassName = MDI_VIEW_CLASS_NAME;
-
- /* Register instance of MDI window class for view displaying. */
- if (RegisterClass(&wc))
- {
- hFrameMenu = LoadMenu(ghModule, "FrameMenu");
- hViewMenu = LoadMenu(ghModule, "ViewMenu");
- hFrameMenuWindow = GetSubMenu(hFrameMenu, 1);
- hViewMenuWindow = GetSubMenu(hViewMenu, 2);
-
- if ((hwnd = CreateWindowEx(0L, MDI_FRAME_CLASS_NAME, MDI_FRAME_CLASS_NAME,
- WS_OVERLAPPED | WS_CAPTION | WS_BORDER |
- WS_THICKFRAME | WS_MAXIMIZEBOX | WS_MINIMIZEBOX |
- WS_CLIPCHILDREN | WS_VISIBLE | WS_SYSMENU,
- CW_USEDEFAULT, CW_USEDEFAULT,
- 600, 500, NULL, hFrameMenu, hInstance, NULL)) != NULL)
- {
- SetWindowLong(hwnd, GWL_USERDATA, 0L);
- /* set initial focus */
- SetFocus(hwnd);
- }
- }
- }
- }
- return(hwnd);
- }
-
- /*-----------------
- * TermApplication -- Free location object and terminate properly from
- * DataViews.
- */
- void TermApplication(void)
- {
- (VOID)VOloDereference( Location );
- TTerminate();
- }
-
- /*-----------------
- * InitDVWindow -- For each MDI client window used to display a view,
- * the DataViews environment must be supplied with the
- * appropriate Windows handle. In this example, a view
- * is loaded with the passed filename for each client window.
- */
- LOCAL BOOL InitDVWindow(HWND hViewWindow, PVIEWDATA pViewData, CHAR *ViewName)
- {
- RECTANGLE Rect = {{-16000, -16000}, {16000, 16000}};
-
- /* Pass the window onto DataViews */
- if ((pViewData->Screen = TscOpenSet( "W:128", NULL,
- V_WIN32_WINDOW_HANDLE, hViewWindow,
- V_ACTIVE_CURSOR, V_END_OF_LIST )) != (OBJECT)NULL)
- {
- /* get a pointer to the function that would */
- /* be the window proc for a window created */
- /* with TscOpenSet */
- GRget(V_WIN32_WINDOWPROC, &MDI_Winproc, V_END_OF_LIST);
- GRset(V_WIN32_DOUBLE_BUFFER, TRUE, V_END_OF_LIST);
-
- /* Load the View, Create Drawport and Draw */
- pViewData->View = TviLoad( ViewName );
- TviOpenData( pViewData->View );
- pViewData->Drawport = TdpCreate( pViewData->Screen, pViewData->View,
- (RECTANGLE*)NULL, &Rect );
- pViewData->QuitButton = TdrGetNamedObject(TviGetDrawing(pViewData->View), "quit");
- TviReadData( pViewData->View );
- TdpDraw( pViewData->Drawport );
-
- /* Create a Timer for DV dynamic updates */
- pViewData->idTimer = SetTimer( hViewWindow, 0, 100, NULL );
- return(TRUE);
- }
- return(FALSE);
- }
-
- /*-----------------
- * RestartTimerOfWindow -- Restore the timer for DV dynamic updates.
- */
- LOCAL BOOL RestartTimerOfWindow(HWND hwnd)
- {
- HANDLE hViewData;
- PVIEWDATA pViewDataFromWindow;
-
- /* Get memory handle for View data associated with window */
- if ((hViewData = (HANDLE) GetWindowLong(hwnd, 0)) != NULL)
- {
- /* Lock memory handle for View data associated with window */
- if ((pViewDataFromWindow = (PVIEWDATA)LocalLock(hViewData)) != NULL)
- pViewDataFromWindow->idTimer = SetTimer( hwnd, 0, 100, NULL );
- LocalUnlock(hViewData);
- }
- }
-
- /*-----------------
- * TermDVWindow -- For each MDI client window used to display a view,
- * upon termination the DataViews environment must be
- * called in order to deallocate and terminate each view
- * properly.
- */
- LOCAL void TermDVWindow(PVIEWDATA pViewData)
- {
- TdpDestroy(pViewData->Drawport);
- TviDestroy(pViewData->View);
- TscClose(pViewData->Screen);
- }
-
- /*-----------------
- * GetViewDataFromWindow -- For each MDI client window used to display a view,
- * view specific data is encapsulated in the window. This provides
- * a mechanism to conveniently associate user data with window data.
- * A copy is made of the encapsulated data for comvience only. Since
- * Windows NT is a fully preemptive operating system, the timer
- * events may occur during the processing of a previous event. This
- * new "thread" may cause application code to reenter a DVtools call
- * currently being processed. In order to avoid this, the timer
- * is "Killed" while in use by GetViewDataFromWindow to lock all
- * other requests out.
- */
- LOCAL BOOL GetViewDataFromWindow(HWND hwnd, PVIEWDATA pViewData)
- {
- HANDLE hViewData;
- PVIEWDATA pViewDataFromWindow;
-
- /* Get memory handle for View data associated with window */
- if ((hViewData = (HANDLE) GetWindowLong(hwnd, 0)) != NULL)
- {
- /* Lock memory handle for View data associated with window */
- if ((pViewDataFromWindow = (PVIEWDATA)LocalLock(hViewData)) != NULL)
- {
- /*
- * Killing the timer for DV dynamic updates is required since NT
- * is multi-threaded. This will keep the application from updating
- * dynamics while in the process of servicing another message. */
- KillTimer( hwnd, pViewDataFromWindow->idTimer );
-
- memcpy(pViewData, pViewDataFromWindow, sizeof(VIEWDATA));
- LocalUnlock(hViewData);
- return YES;
- }
- else
- MessageBox(ghwndFrame, MDI_ERROR_MEM_LOCK, MDI_ERROR, MB_OK);
- }
- return NO;
- }
-
- /*-----------------
- * CreateMDIView -- For each MDI client window used to display a view,
- * we need to allocate memory for view data, create the
- * window from the pre-registered class, and supply the
- * view data to the window in order to associate it.
- */
- LOCAL BOOL CreateMDIView(HWND hwnd, CHAR *ViewName)
- {
- HANDLE hViewData;
- PVIEWDATA pViewData;
- MDICREATESTRUCT mdicreate;
- HWND hwndChildWindow;
-
- /* Allocate memory for View data to be associated with window */
- if (hViewData = LocalAlloc(LHND, (WORD) sizeof(VIEWDATA)))
- {
- if ((pViewData = (PVIEWDATA)LocalLock(hViewData)) == NULL)
- MessageBox(ghwndFrame, MDI_ERROR_MEM_LOCK, MDI_ERROR, MB_OK);
-
- mdicreate.szClass = MDI_VIEW_CLASS_NAME;
- mdicreate.szTitle = (LPTSTR)ViewName;
- mdicreate.hOwner = ghModule;
- mdicreate.x = mdicreate.y = mdicreate.cx = mdicreate.cy = CW_USEDEFAULT;
- mdicreate.style = 0L;
- /* Supplying the handle of the per MDI View data to the MDI Window */
- mdicreate.lParam = (LONG) hViewData;
-
- /* Create Child Window */
- if ((hwndChildWindow = (HANDLE) SendMessage(ghwndClient, WM_MDICREATE,
- 0L, (LONG)(LPMDICREATESTRUCT)&mdicreate)) == NULL)
- {
- MessageBox(ghwndFrame, MDI_ERROR_CREATE_WIN, MDI_ERROR, MB_OK);
- return 0L;
- }
- LocalUnlock(hViewData);
- return YES;
- }
- else
- {
- MessageBox(ghwndFrame, MDI_ERROR_MEM_ALLOC, MDI_ERROR, MB_OK);
- }
- return NO;
- }
-
- /*-----------------
- * WinMain -- All windows applications contain a unique main function. The
- * only significant difference with this function is that the
- * the windows message loop is interpreted for MDI accelerator
- * messages and translated.
- */
- int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
- LPSTR lpCmdLine, int nShowCmd)
- {
- MSG msg;
- HANDLE hAccel;
-
- /* Initialize DataViews and windows. */
- if ((ghwndFrame = InitApplication(hInstance)) != NULL)
- {
- if (!(hAccel = LoadAccelerators (hInstance, MAKEINTRESOURCE(MDI_ACCEL_ID))))
- MessageBox(ghwndFrame, MDI_ERROR_RESLOAD_ACCEL, MDI_ERROR, MB_OK);
-
- /* Here is the windows event loop. */
- while (GetMessage(&msg, NULL, 0, 0))
- {
- if (!TranslateAccelerator(ghwndFrame, hAccel, &msg) &&
- !TranslateMDISysAccel(ghwndClient, &msg))
- {
- TranslateMessage(&msg);
- DispatchMessage(&msg);
- }
- }
- /* Normally windows will destroy an attached menu at the time the window
- * is destroyed. In this example the View menu is not attached so it must
- * be destroyed here.
- */
- DestroyMenu(hViewMenu);
- }
- else
- MessageBox(ghwndFrame, MDI_ERROR_WIN_INIT, MDI_ERROR, MB_OK);
- return msg.wParam;
-
- UNREFERENCED_PARAMETER(lpCmdLine);
- UNREFERENCED_PARAMETER(nShowCmd);
- UNREFERENCED_PARAMETER(hInstance);
- UNREFERENCED_PARAMETER(hPrevInstance);
- }
-
-
- /*-----------------
- * FrameWndProc -- Each window must have a function that is used to "filter"
- * windows messages for all those interested in. This function
- * is used for interpreting all messages that are applicable
- * to the frame window.
- */
- long APIENTRY FrameWndProc(HWND hwnd, UINT message, DWORD wParam,
- LONG lParam)
- {
- CLIENTCREATESTRUCT clientcreate;
- FARPROC lpfnEnum;
-
- switch (message)
- {
- /* The frame window has been created. */
- case WM_CREATE:
- SetWindowLong(hwnd, 0, (LONG)NULL);
- clientcreate.hWindowMenu = hFrameMenuWindow;
- clientcreate.idFirstChild = 1;
-
- ghwndClient = CreateWindow("MDICLIENT", NULL,
- WS_CHILD | WS_CLIPCHILDREN | WS_VISIBLE,
- 0,0,0,0,
- hwnd, NULL, ghModule, (LPVOID)&clientcreate);
- return 0L;
-
- case WM_ACTIVATE:
- {
- /* this message is sent when the message box is */
- /* dismissed */
- if ( ( LOWORD(wParam) == WA_ACTIVE ) ||
- ( LOWORD(wParam) == WA_CLICKACTIVE ) )
- ok_to_draw = TRUE;
- return 0L;
- }
-
- case WM_CANCELMODE:
- {
- /* this message will be sent when the graph view is */
- /* is sized too small and a message box displays */
- /* the viewport too small message. redrawing the */
- /* view while the message box is up will result in */
- /* an endless stream of errors. */
- ok_to_draw = FALSE;
- return 0L;
- }
-
- case WM_COMMAND:
-
- switch (LOWORD(wParam))
- {
- /* Default MDI functionality. */
- case MDI_TILE:
- SendMessage(ghwndClient, WM_MDITILE, 0L, 0L);
- return 0L;
- case MDI_CASCADE:
- SendMessage(ghwndClient, WM_MDICASCADE, 0L, 0L);
- return 0L;
- case MDI_ARRANGE:
- SendMessage(ghwndClient, WM_MDIICONARRANGE, 0L, 0L);
- return 0L;
-
- /* Add MDI View chosen by user from menu options. */
- case MDI_ADD_LIGHTNING_VIEW:
- CreateMDIView(hwnd, LIGHTNING_VIEW_NAME);
- return 0L;
- case MDI_ADD_WINDOW_VIEW:
- CreateMDIView(hwnd, WINDOW_VIEW_NAME);
- return 0L;
- case MDI_ADD_ELLIPSE_VIEW:
- CreateMDIView(hwnd, ELLIPSE_VIEW_NAME);
- return 0L;
-
- /* Launch about dialog. */
- case MDI_ABOUT:
- if (DialogBox(ghModule, MDI_ABOUT_DLG_CLASS_NAME, ghwndFrame, (DLGPROC)About) == -1)
- MessageBox(ghwndFrame, MDI_ERROR_CREATE_DLG, MDI_ERROR, MB_OK);
- return 0L;
-
- /* A request to destroy has been passed from the exit menu. */
- case MDI_EXIT:
- SendMessage(hwnd, WM_CLOSE, 0, 0L);
- return 0L;
-
- /* Pass appropriate messages to the active child. */
- case MDI_ZOOM_IN:
- case MDI_ZOOM_OUT:
- {
- HWND hActiveChild;
-
- if (hActiveChild = (HANDLE) SendMessage(ghwndClient, WM_MDIGETACTIVE, 0L, 0L))
- SendMessage(hActiveChild, WM_COMMAND, wParam, lParam);
- return 0L;
- }
-
- /* Inapplicable messages are passed on to parent. */
- default:
- return DefFrameProc(hwnd, ghwndClient, message, wParam, lParam);
- }
-
- /* A request to close has been passed. */
- case WM_QUERYENDSESSION:
- case WM_CLOSE:
- {
- lpfnEnum = MakeProcInstance((FARPROC)CloseEnumProc, hInst);
- EnumChildWindows(hwnd, lpfnEnum, 0L);
- FreeProcInstance(lpfnEnum);
-
- /* Check to see if this is the icon title window. Do not send message if it is. */
- if (GetWindow(ghwndClient, GW_CHILD) != NULL)
- return 0L;
- SendMessage(hwnd, WM_DESTROY, 0, 0L);
- return 0L;
- }
-
- /* A request to destroy has been passed, possibly from a close message. */
- case WM_DESTROY:
- {
- TermApplication();
- PostQuitMessage(0);
- return 0L;
- }
-
- /* Inapplicable messages are passed on to parent. */
- default:
- return DefFrameProc(hwnd, ghwndClient, message, wParam, lParam);
- }
- }
-
- /*-----------------
- * CloseEnumProc -- This function sends a WM_MDIRESTORE message to each child
- * window followed by a WM_QUERYENDSESSION and possibly a
- * WM_MDIDESTROY. This is not done for the icon title window.
- */
- BOOL APIENTRY CloseEnumProc(
- HWND hwnd,
- LONG lParam)
- {
- /* Check to see if this is the icon title window. */
- if (GetWindow(hwnd, GW_OWNER))
- return 1;
-
- SendMessage(GetParent(hwnd), WM_MDIRESTORE, (WPARAM)hwnd, 0L);
-
- if (!SendMessage(hwnd, WM_QUERYENDSESSION, 0, 0L))
- return 1;
-
- SendMessage(GetParent(hwnd), WM_MDIDESTROY, (WPARAM)hwnd, 0L);
- return 1;
- }
-
- /*-----------------
- * ViewWndProc -- Each window must have a function that is used to "filter"
- * windows messages for all those interested in. This function
- * is used for interpreting all messages that are applicable
- * to the client or view window. If they are not, then the
- * messages are passed onto its parent by NOT returning a 0 but
- * returning with DefMDIChildProc.
- */
- long APIENTRY ViewWndProc(
- HWND hwnd,
- UINT message,
- DWORD wParam,
- LONG lParam)
- {
-
-
- switch (message)
- {
-
- case WM_COMMAND:
- {
- /* Passed messages from parent. */
- switch (LOWORD(wParam))
- {
- VIEWDATA ViewData;
- DOUBLE Scale;
-
- case MDI_ZOOM_IN:
- if (GetViewDataFromWindow(hwnd, &ViewData))
- {
- if ((Scale = TdpGetScale(ViewData.Drawport)) < 0.1)
- {
- TdpZoom(ViewData.Drawport, (DOUBLE)1.5);
- TscRedraw(ViewData.Screen, NULL);
- }
- RestartTimerOfWindow(hwnd);
- }
- return 0L;
- case MDI_ZOOM_OUT:
- if (GetViewDataFromWindow(hwnd, &ViewData))
- {
- if ((Scale = TdpGetScale(ViewData.Drawport)) > 0.001)
- {
- TdpZoom(ViewData.Drawport, (DOUBLE)0.75);
- TscRedraw(ViewData.Screen, NULL);
- }
- RestartTimerOfWindow(hwnd);
- }
- return 0L;
- }
- }
-
- /*
- * This message is generated from the timers set upon window initialization
- * for the handling of dynamic updates.
- */
- case WM_TIMER:
- {
- VIEWDATA ViewData;
-
- if (GetViewDataFromWindow(hwnd, &ViewData))
- {
- if (ok_to_draw == TRUE)
- UpdateDVwindow(&ViewData);
- RestartTimerOfWindow(hwnd);
- }
- return 0L;
- }
-
- /*
- * These messages are assumed to be events that this DataViews
- * example is interested in. At this point is typically where an
- * application will decide whether a message is to be handled by
- * windows code or by DataViews event handling facilities.
- */
- case WM_LBUTTONDOWN:
- case WM_RBUTTONDOWN:
- {
- VIEWDATA ViewData;
- MSG Message; /* structure storing details of Windows events */
-
- /* Fill structure with appropriate data. */
- Message.hwnd = hwnd;
- Message.message = message;
- Message.wParam = wParam;
- Message.lParam = lParam;
- /*
- * GetMessageTime retrieves the last time posted by the message just
- * retrieved.
- */
- Message.time = GetMessageTime();
- Message.pt.x = LOWORD(lParam);
- Message.pt.y = HIWORD(lParam);
-
- if (GetViewDataFromWindow(hwnd, &ViewData))
- {
- if (HandleDVwindowEvents(&ViewData, &Message))
- {
- /* The YESNO dialog is used to demonstrate DataViews to windows interaction. */
- if (YesNo("Do you really want to close the View window?"))
- SendMessage(hwnd, WM_CLOSE, 0L, 0L);
- }
- RestartTimerOfWindow(hwnd);
- }
- return 0L;
- }
-
- case WM_PAINT:
- {
- PAINTSTRUCT ps;
-
- /* This will call the DV window procedure. This will generate
- * expose and resize events as a DataViews only program would.
- */
- if ( MDI_Winproc != NULL )
- return CallWindowProc(MDI_Winproc, hwnd, message, wParam, lParam );
- BeginPaint(hwnd, &ps);
- EndPaint(hwnd, &ps);
- return 0L;
- }
-
- /* Some portion of the view window has been exposed. VI_EXPOSE comes
- * from the DataViews window procedure's handling of the WM_PAINT message.
- * VI_EXPOSE is defined in dvGR.h.
- */
- case VI_EXPOSE:
- {
- VIEWDATA ViewData;
- MSG win_msg;
- WINEVENT we;
-
- win_msg.hwnd = hwnd;
- win_msg.message = message;
- win_msg.wParam = wParam;
- win_msg.lParam = lParam;
-
- /* This call must be made on a VI_EXPOSE to keep the DataViews */
- /* driver in sync with itself. Without this, all heck breaks loose. */
-
- GRwe_convert(&win_msg,&we);
-
- if (GetViewDataFromWindow(hwnd, &ViewData))
- {
- if ( ok_to_draw == TRUE )
- TscRedraw(ViewData.Screen, NULL);
- RestartTimerOfWindow(hwnd);
- }
- return 0L;
- }
-
- /*
- * Potentially, you can set different menus for different MDI
- * views which is currently being active.
- */
- case WM_MDIACTIVATE:
- if ((HWND) lParam == hwnd)
- {
- SendMessage(GetParent(hwnd), WM_MDISETMENU,
- (DWORD) hViewMenu,
- (LONG) hViewMenuWindow) ;
- DrawMenuBar(GetParent(GetParent(hwnd))) ;
- }
- return 0L;
-
- /*
- * Whenever the client window is about to be resized, its tracking size may
- * be changed to override the system default for that window. In this case
- * a TscReset will not be able to scale properly to an extremely small window.
- */
- case WM_GETMINMAXINFO:
- {
- LPMINMAXINFO lpmmi = (LPMINMAXINFO)lParam;
-
- if ((lpmmi->ptMinTrackSize.y < 100)||(lpmmi->ptMinTrackSize.x < 100))
- {
- lpmmi->ptMinTrackSize.x = 100;
- lpmmi->ptMinTrackSize.y = 100;
- }
- break;
- }
-
- /*
- * This client window has been resized or the frame window has been resized and
- * this client needs to resize also. VI_RESIZE comes from the DataViews window
- * procedure's handling of the WM_PAINT message. VI_RESIZE is defined in dvGR.h.
- */
- case VI_RESIZE:
- case WM_SIZE:
- {
- VIEWDATA ViewData;
-
- if (GetViewDataFromWindow(hwnd, &ViewData))
- {
- TscReset(ViewData.Screen);
- RestartTimerOfWindow(hwnd);
- }
- break;
- }
-
- /*
- * Create the control window for this MDI child and saves its handle
- * in the View data structure.
- */
- case WM_CREATE:
- {
- PVIEWDATA pViewData;
- HANDLE hViewData;
- CHAR ViewName[MAXSTRING];
-
- /*
- * View data was allocated in CreateMDIView, which is called in the
- * MDI_ADD_XXX_VIEW case of FrameWndProc.
- */
- if (hViewData = (HANDLE) ((LPMDICREATESTRUCT) ((LPCREATESTRUCT) lParam)->lpCreateParams)->lParam)
- {
- if ((pViewData = (PVIEWDATA)LocalLock(hViewData)) == NULL)
- MessageBox(ghwndFrame, MDI_ERROR_MEM_LOCK, MDI_ERROR, MB_OK);
-
- GetWindowText(hwnd, (LPTSTR)ViewName, MAXSTRING);
-
- /*
- * The initialization of the DataViews Windows instance
- * is done at its WM_CREATE message rather than at the time
- * the window create request was made in order to ensure that
- * the view data memory is set by SetWindowLong AFTER the
- * th DV window is initalized by InitDVWindow.
- */
- if (!InitDVWindow(hwnd, pViewData, ViewName))
- MessageBox(hwnd, MDI_ERROR_DV_INIT, MDI_ERROR, MB_OK);
-
- /* Save the handle to VIEWDATA in our window structure */
- SetWindowLong(hwnd, 0, (LONG) hViewData);
- LocalUnlock(hViewData);
- }
- else
- {
- MessageBox(ghwndFrame, MDI_ERROR_MEM_ALLOC, MDI_ERROR, MB_OK);
- }
- break;
- }
-
- /*
- * MDI windows use the WM_QUERYENDSESSION or WM_CLOSE message to see if
- * the application/user is sure they wish to procede with the action.
- * (typically where a "File not saved, are you sure you wish to close?"
- * decision is made)
- */
- case WM_QUERYENDSESSION:
- case WM_CLOSE:
- SendMessage(GetParent(hwnd), WM_MDISETMENU,
- (DWORD) hFrameMenu,
- (LONG) hFrameMenuWindow) ;
- DrawMenuBar(GetParent(GetParent(hwnd))) ;
- break;
-
- /*
- * WM_DESTROY is where the system is comitted to the termination of the
- * window and where the view cleanup must be.
- */
- case WM_DESTROY:
- {
- VIEWDATA ViewData;
-
- /* It is necessary to free and zero the view data associated
- * with this window immediately to avoid further use of this data
- * if events are generated. This is only an issue with Windows NT
- * since it is multi threaded. */
- if (GetViewDataFromWindow(hwnd, &ViewData))
- {
- LocalFree((HANDLE) GetWindowLong(hwnd, 0));
- SetWindowLong(hwnd, 0, (LONG)NULL);
-
- /* Free the View data that is associated with Window. */
- TermDVWindow(&ViewData);
- }
- break;
- }
-
- /* Inapplicable messages are passed on to parent. */
- default:
- return DefMDIChildProc(hwnd, message, wParam, lParam);
- } /* switch */
-
- /* Inapplicable messages are passed on to parent. */
- return DefMDIChildProc(hwnd, message, wParam, lParam);
- }
-
- /*-----------------
- * YesNo -- This is a generic dialog used to demonstrate message setting,
- * dialog creation, and handling.
- */
- BOOL YesNo (CHAR *Message)
- {
- int iReturnValue;
-
- YesNoMessage = (LPCTSTR)Message;
- if ((iReturnValue = DialogBox(ghModule, "YESNO", ghwndFrame, (DLGPROC)YesNoProc)) == -1)
- {
- MessageBox(ghwndFrame, MDI_ERROR_CREATE_DLG, MDI_ERROR, MB_OK);
- return NO;
- }
-
- if (iReturnValue == IDYES)
- return YES;
- return NO;
- }
-
- /*-----------------
- * YesNoProc -- This is a generic dialog proc used to demonstrate message setting,
- * dialog creation, and handling.
- */
- BOOL CALLBACK YesNoProc (HWND hDlg, UINT message, DWORD wParam,
- LONG lParam)
- {
- switch (message)
- {
- /*
- * This is the first time the dialog is setup, here the example uses
- * a predefined message ID for prompting user input.
- */
- case WM_INITDIALOG:
- SetDlgItemText(hDlg, MDI_YESNO_MESSAGE, YesNoMessage);
- return TRUE;
-
- case WM_COMMAND:
- /* Only terminate this dialog with a IDYES or IDNO message. */
- if ((wParam == IDYES)||(wParam == IDNO))
- EndDialog(hDlg, wParam);
- break;
- }
- return FALSE;
-
- UNREFERENCED_PARAMETER(lParam);
- UNREFERENCED_PARAMETER(hDlg);
- }
-
- /*-----------------
- * About -- This is a generic dialog used by most windows applications.
- */
- BOOL CALLBACK About (HWND hDlg, UINT message, DWORD wParam,
- LONG lParam)
- {
- switch (message)
- {
- case WM_INITDIALOG:
- return TRUE;
-
- case WM_COMMAND:
- /* Only terminate this dialog with a IDOK message. */
- if (wParam == IDOK)
- EndDialog(hDlg, wParam);
- break;
- }
- return FALSE;
-
- UNREFERENCED_PARAMETER(lParam);
- UNREFERENCED_PARAMETER(hDlg);
- }
-
-